<?php
abstract class Report
{
	protected $total;					// Total Elements
	protected $start;					// Start render at element...
	protected $pageElements;		// Number of elements by page
	protected $info;					// Buffer of elements
	protected $getVar;				// Variable to be used on $_GET
	protected $cacheName;			// Cache name on $_SESSION
	protected $fetchObject;			// Ref. to object who implements fetch($start); getControlTotal(); getControlPage();
	protected $clear = false;		// Object was clear now?

	abstract public function render();
	
	protected function fetchFromObject()
	{
		$this->setInfo($this->fetchObject->fetch($this->start));
	}
	protected function writeToCache()
	{
		@session_start();
		$_SESSION[$this->cacheName] = "INIT";
		$_SESSION[$this->cacheName."_total"] = serialize($this->total);
		$_SESSION[$this->cacheName."_start"] = serialize($this->start);
		$_SESSION[$this->cacheName."_last"] = serialize($this->last);
		$_SESSION[$this->cacheName."_bufferPointer"] = serialize($this->bufferPointer);
		$_SESSION[$this->cacheName."_bufferSize"] = serialize($this->bufferSize);
		$_SESSION[$this->cacheName."_pageElements"] = serialize($this->pageElements);
		$_SESSION[$this->cacheName."_info"] = serialize($this->info);
	}
	protected function readFromCache()
	{
		@session_start();
		if(isset($_SESSION[$this->cacheName]))
		{
			$this->total = unserialize($_SESSION[$this->cacheName."_total"]);
			$this->start = unserialize($_SESSION[$this->cacheName."_start"]);
			$this->last = unserialize($_SESSION[$this->cacheName."_last"]);
			$this->bufferPointer = unserialize($_SESSION[$this->cacheName."_bufferPointer"]);
			$this->bufferSize = unserialize($_SESSION[$this->cacheName."_bufferSize"]);
			$this->pageElements = unserialize($_SESSION[$this->cacheName."_pageElements"]);
			$this->info = unserialize($_SESSION[$this->cacheName."_info"]);
			return true;
		}
		return false;
	}
	protected function clear()
	{
	}
	public function setTotal($total)
	{
		$this->total = $total;
		$this->setStart(0);
	}
	public function setStart($start)
	{
		if($start < $this->total)
			$this->start = $start;
		else if(($start - $this->pageElements) > 0)
			$this->start = $start - $this->pageElements;
		else
			$this->start = 0;
	}
	public function setPageElements($pageElements)
	{
		$this->pageElements = $pageElements;
	}
	public function setInfo($info)
	{
		$this->info = $info;
	}
}
?>